// 存放的是 个人信息模块的数据

import { User, UserProfile } from '@/types/data'
import { RootAction } from '@/types/store'

// {
//   name:'zs',
//   age:18
// }
type InitValueType = {
  user: User
  userProfile: UserProfile
}

const initValue: InitValueType = {
  user: {}, // 基本
  userProfile: {}, // 详情
  // xx: {}
} as InitValueType

export default function profileReducer(state = initValue, action: RootAction) {
  // { type: 'profile/set_user', payload: res.data.data }
  if (action.type === 'profile/set_user') {
    return {
      ...state,
      user: action.payload,
    }
  }

  // { type: 'profile/set_user_profile', payload: res.data.data }
  if (action.type === 'profile/set_user_profile') {
    return {
      ...state,
      userProfile: action.payload,
    }
  }

  return state
}
